﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Api_Dto
{
    /// <summary>
    /// api返回值
    /// </summary>
    [DataContract]
    public class ApiMessageEntity
    {
        /// <summary>
        /// 返回-1：身份验证失败，0：失败，1：成功， 2：异常（catch捕捉）
        /// </summary>
        [DataMember(Order = 0)]
        public ApiReturnState requstresult
        { get; set; }

        /// <summary>
        /// 如果调用失败，则显示失败原因
        /// </summary>
        [DataMember(Order = 1)]
        public string reason
        { get; set; }

        /// <summary>
        /// 操作类型（Get、Post、Put、Delete）
        /// </summary>
        [DataMember(Order = 2)]
        public string operation
        { get; set; }

        /// <summary>
        /// 要返回的数据
        /// </summary>
        [DataMember(Order = 3)]
        public object data
        { get; set; }

        /// <summary>
        /// 返回条数
        /// </summary>
        [DataMember(Order = 4)]
        public int total
        { get; set; }

        /// <summary>
        /// 是否最后一条
        /// </summary>
        [DataMember(Order = 4)]
        public bool isEnd
        { get; set; }

        /// <summary>
        /// API服务返回数据载体
        /// </summary>
        /// <param name="requstresult">返回</param>
        /// <param name="reason">如果调用失败，则显示失败原因</param>
        /// <param name="operation">操作类型（Get、Post、Put、Delete）</param>
        /// <param name="data">要返回的数据</param>
        /// <returns></returns>
        public static ApiMessageEntity ReturnData(ApiReturnState requstresult, string reason, string operation, object data = null)
        {
            //HttpContext.Current.Session["APIBaseUser"] = null;
            //HttpContext.Current.Session["API"] = null;
            return new ApiMessageEntity()
            {
                requstresult = requstresult,
                reason = reason,
                operation = operation,
                data = data
            };
        }

        /// <summary>
        /// API服务返回数据载体
        /// </summary>
        /// <param name="requstresult">返回</param>
        /// <param name="reason">如果调用失败，则显示失败原因</param>
        /// <param name="operation">操作类型（Get、Post、Put、Delete）</param>
        /// <param name="data">要返回的数据</param>
        /// <param name="total">结果条数</param>
        /// <returns></returns>
        public static ApiMessageEntity ReturnData(ApiReturnState requstresult, string reason, string operation, object data, int total, bool isEnd = true)
        {
            //HttpContext.Current.Session["APIBaseUser"] = null;
            //HttpContext.Current.Session["API"] = null;
            return new ApiMessageEntity()
            {
                requstresult = requstresult,
                reason = reason,
                operation = operation,
                data = data,
                total = total,
                isEnd = isEnd
            };
        }
    }
    /// <summary>
    /// 调用接口的方式
    /// </summary>
    public enum ApiOperation
    {
        /// <summary>
        /// Get
        /// </summary>
        Get = 1,
        /// <summary>
        /// Post
        /// </summary>
        Post = 2,
        /// <summary>
        /// Put
        /// </summary>
        Put = 3,
        /// <summary>
        /// Delete
        /// </summary>
        Delete = 4
    }

    /// <summary>
    /// 接口调用的返回状态
    /// </summary>
    public enum ApiReturnState
    {
        /// <summary>
        /// 身份验证失败
        /// </summary>
        AuthenticationFailure = -1,
        /// <summary>
        /// 失败
        /// </summary>
        Fail = 0,
        /// <summary>
        /// 成功
        /// </summary>
        Success = 1,
        /// <summary>
        /// 发生异常
        /// </summary>
        Exception = 2
    }

    /// <summary>
    /// 数据状态
    /// </summary>
    public enum DataState
    {
        /// <summary>
        /// 超标
        /// </summary>
        IsOver = 0,
        /// <summary>
        /// 异常
        /// </summary>
        IsException = 1
    }
}
